import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig(
  ({ command, mode }) => {
    return {
      // 基础配置
      base: '/',
      // 服务端渲染
      server: {
        https: false, // https是否开启
        port: 80, // 端口
        host: '0.0.0.0', // 监听的IP地址
        proxy: {
          '/api': {
            target: 'http://127.0.0.1:60002',
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, '')
          }
        }
      },
      resolve: {
        alias: {
          '@': path.resolve(__dirname, './src'),
          vue: 'vue/dist/vue.esm-bundler.js'
        }
      },
      // 配置按需加载
      plugins: [
        vue(),
        AutoImport({
          resolvers: [AntDesignVueResolver()]
        }),
        Components({
          resolvers: [AntDesignVueResolver()]
        })
      ],
      css: {
        preprocessorOptions: {
          scss: {
            additionalData: ''
          }
        }
      }
    }
  }
)
